package com.java2110.service.impl;

import com.java2110.dto.SubjectsDTO;
import com.java2110.entity.Subjects;
import com.java2110.mapper.SubjectsMapper;
import com.java2110.service.SubjectService;
import com.java2110.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author admin
 * @since 2025-05-2025/5/23 15:33
 */
@Service
@Transactional
public class SubjectServiceImpl implements SubjectService {
    @Autowired
    private SubjectsMapper subjectsMapper;
    @Override
    public PageUtils<Subjects> find(SubjectsDTO subjectsDTO) {
        PageUtils<Subjects> pageUtils = new PageUtils<>();
        Integer startIndexNo = (subjectsDTO.getStartPageNo()-1)*subjectsDTO.getPageSize();
        subjectsDTO.setStartIndexNo(startIndexNo);
        List<Subjects> data = subjectsMapper.find(subjectsDTO);
        Integer count = subjectsMapper.count();
        pageUtils.setCurrentPageNo(subjectsDTO.getStartPageNo());
        pageUtils.setTotalCount(count);
        pageUtils.setData(data);
        return pageUtils;
    }

    @Override
    public Subjects findById(Integer id) {
        return subjectsMapper.findById(id);
    }

    @Override
    public Integer update(Integer id) {
        return subjectsMapper.update(id);
    }
}
